home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / harvard.perl < prev    next >
Text File  |  1994-06-19  |  21KB  |  787 lines

  1. # harvard.perl
  2. # Copyright 1994 - thorsten schnier (thorsten@arch.su.edu.au)
  3. # key center of design computing, university of sydney
  4. #
  5. # Change Log:
  6. # ===========
  7. #
  8. # 07-JUN-94 first attempt
  9. # 16-JUN-94 changes for harvard 2.0
  10. #           (star and starstar commands)
  11.  
  12.  
  13. package main;
  14.  
  15. $cite_mark = '<tex2html_cite_mark>';
  16. $citefull_mark = '<tex2html_citefull_mark>';
  17. $citeshort_mark = '<tex2html_citeshort_mark>';
  18. $citename_mark = '<tex2html_citename_mark>';
  19. $citenamefull_mark = '<tex2html_citenamefull_mark>';
  20. $citenameshort_mark = '<tex2html_citenameshort_mark>';
  21. $citekey_mark = '<tex2html_citekey_mark>';
  22. $citeyear_mark = '<tex2html_citeyear_mark>';
  23.  
  24. $harvard_left = '(';
  25. $harvard_right = ')';
  26. $harvardyear_left = '(';
  27. $harvardyear_right = ')';
  28. $harvard_cite_separator = $harvard_agsm_cite_separator = ', ';
  29. $harvard_year_separator = $harvard_agsm_year_separator = " ";
  30. $harvard_agsm_and = '&';
  31. $harvard_dcu_cite_separator = "; ";
  32. $harvard_dcu_year_separator = ", ";
  33. $harvard_dcu_and = 'and';
  34. $harvard_and = $harvard_agsm_and;
  35. $harvard_default = 1;
  36. $harvard_full = 0;
  37.  
  38. # the citation commands
  39. # This just creates a link from a label (yet to be determined) to the 
  40. # cite_key in the citation file.
  41. # use different markers, depending on the style of the citation used
  42.  
  43. #changes to latex2html-version:
  44. #insert separating sign, use optional text argument, use brackets 
  45. #according to cite-mode, and reverse order of cites (to correct order)
  46.  
  47.  
  48.  
  49. sub do_cmd_cite {
  50.     local($_) = @_;
  51.     local($text, $dummy) = &get_next_optional_argument;
  52.     s/$next_pair_pr_rx//o;
  53.     local($cite_key) = $2;
  54.     local ($first) = 1 ;
  55.     local ($result);
  56.     if ($cite_key) {
  57.     foreach $cite_key (split(/,/,$cite_key)) {
  58.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  59.         $result = join ('', $result,
  60.                 $first ? $harvard_left : $harvard_cite_separator,
  61.                 "<A HREF=#$cite_key>$citekey_mark", 
  62.                 '##', $cite_key, $cite_mark, 
  63.                 $harvard_year_separator,
  64.                 '##', $cite_key, $citeyear_mark,
  65.                 "<\/A>");
  66.         $first = 0;
  67.     }
  68.     join ('', 
  69.           $result,
  70.           $text ? ($harvard_agsm_cite_separator, $text):'', 
  71.           $harvard_right,
  72.           $_);
  73.     }
  74.     else {warn "Cannot find citation argument\n";}
  75. }
  76.  
  77.  
  78. sub do_cmd_citestar {
  79.     local($_) = @_;
  80.     local($text, $dummy) = &get_next_optional_argument;
  81.     s/$next_pair_pr_rx//o;
  82.     local($cite_key) = $2;
  83.     local ($first) = 1 ;
  84.     local ($result);
  85.     if ($cite_key) {
  86.     foreach $cite_key (split(/,/,$cite_key)) {
  87.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  88.         $result = join ('', $result,
  89.                 $first ? $harvard_left : $harvard_cite_separator,
  90.                 "<A HREF=#$cite_key>$citekey_mark", 
  91.                 '##', $cite_key, $citefull_mark, 
  92.                 $harvard_year_separator,
  93.                 '##', $cite_key, $citeyear_mark,
  94.                 "<\/A>");
  95.         $first = 0;
  96.     }
  97.     join ('', 
  98.           $result,
  99.           $text ? ($harvard_agsm_cite_separator, $text):'', 
  100.           $harvard_right,
  101.           $_);
  102.     }
  103.     else {warn "Cannot find citation argument\n";}
  104. }
  105.  
  106.  
  107. sub do_cmd_citestarstar {
  108.     local($_) = @_;
  109.     local($text, $dummy) = &get_next_optional_argument;
  110.     s/$next_pair_pr_rx//o;
  111.     local($cite_key) = $2;
  112.     local ($first) = 1 ;
  113.     local ($result);
  114.     if ($cite_key) {
  115.     foreach $cite_key (split(/,/,$cite_key)) {
  116.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  117.         $result = join ('', $result,
  118.                 $first ? $harvard_left : $harvard_cite_separator,
  119.                 "<A HREF=#$cite_key>$citekey_mark", 
  120.                 '##', $cite_key, $citeshort_mark, 
  121.                 $harvard_year_separator,
  122.                 '##', $cite_key, $citeyear_mark,
  123.                 "<\/A>");
  124.         $first = 0;
  125.     }
  126.     join ('', 
  127.           $result,
  128.           $text ? ($harvard_agsm_cite_separator, $text):'', 
  129.           $harvard_right,
  130.           $_);
  131.     }
  132.     else {warn "Cannot find citation argument\n";}
  133. }
  134.  
  135.  
  136.  
  137. sub do_cmd_citeaffixed {
  138.     local($_) = @_;
  139.     local($text, $dummy) = &get_next_optional_argument;
  140.     s/$next_pair_pr_rx//o;
  141.     local($cite_key) = $2;
  142.     s/$next_pair_pr_rx//o;
  143.     local($comment) = $2;
  144.     local ($first) = 1;
  145.     local ($result);
  146.      if ($cite_key) {
  147.     foreach $cite_key (split(/,/,$cite_key)) {
  148.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  149.         $result = join ('', $result, 
  150.                 $first? ($harvard_left, $comment, " ")
  151.                          : $harvard_cite_separator,
  152.                 "<A HREF=#$cite_key>$citekey_mark", 
  153.                 '##', $cite_key, $cite_mark, 
  154.                 $harvard_year_separator,
  155.                 '##', $cite_key,$citeyear_mark, 
  156.                 "<\/A>");
  157.         $first = 0;
  158.     }
  159.     join('',
  160.          $result, 
  161.          $text? ($harvard_agsm_cite_separator, $text):'', 
  162.          $harvard_right,
  163.          $_);
  164.     }
  165.     else {warn "Cannot find citation argument\n";}
  166. }
  167.  
  168.  
  169. sub do_cmd_citeaffixedstar {
  170.     local($_) = @_;
  171.     local($text, $dummy) = &get_next_optional_argument;
  172.     s/$next_pair_pr_rx//o;
  173.     local($cite_key) = $2;
  174.     s/$next_pair_pr_rx//o;
  175.     local($comment) = $2;
  176.     local ($first) = 1;
  177.     local ($result);
  178.      if ($cite_key) {
  179.     foreach $cite_key (split(/,/,$cite_key)) {
  180.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  181.         $result = join ('', $result, 
  182.                 $first? ($harvard_left, $comment, " ")
  183.                          : $harvard_cite_separator,
  184.                 "<A HREF=#$cite_key>$citekey_mark", 
  185.                 '##', $cite_key, $citefull_mark, 
  186.                 $harvard_year_separator,
  187.                 '##', $cite_key,$citeyear_mark, 
  188.                 "<\/A>");
  189.         $first = 0;
  190.     }
  191.     join('',
  192.          $result, 
  193.          $text? ($harvard_agsm_cite_separator, $text):'', 
  194.          $harvard_right,
  195.          $_);
  196.     }
  197.     else {warn "Cannot find citation argument\n";}
  198. }
  199.  
  200. sub do_cmd_citeaffixedstarstar {
  201.     local($_) = @_;
  202.     local($text, $dummy) = &get_next_optional_argument;
  203.     s/$next_pair_pr_rx//o;
  204.     local($cite_key) = $2;
  205.     s/$next_pair_pr_rx//o;
  206.     local($comment) = $2;
  207.     local ($first) = 1;
  208.     local ($result);
  209.      if ($cite_key) {
  210.     foreach $cite_key (split(/,/,$cite_key)) {
  211.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  212.         $result = join ('', $result, 
  213.                 $first? ($harvard_left, $comment, " ")
  214.                          : $harvard_cite_separator,
  215.                 "<A HREF=#$cite_key>$citekey_mark", 
  216.                 '##', $cite_key, $citeshort_mark, 
  217.                 $harvard_year_separator,
  218.                 '##', $cite_key,$citeyear_mark, 
  219.                 "<\/A>");
  220.         $first = 0;
  221.     }
  222.     join('',
  223.          $result, 
  224.          $text? ($harvard_agsm_cite_separator, $text):'', 
  225.          $harvard_right,
  226.          $_);
  227.     }
  228.     else {warn "Cannot find citation argument\n";}
  229. }
  230.  
  231.  
  232.  
  233. #similar to cite
  234. #no multiple cites allowed !
  235.  
  236. sub do_cmd_citeasnoun {
  237.     local($_) = @_;
  238.     local($text, $dummy) = &get_next_optional_argument;
  239.     s/$next_pair_pr_rx//o;
  240.     local($cite_key) = $2;
  241.     if ($cite_key) {
  242.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  243.     join ('',
  244.           "<A HREF=#$cite_key>$citekey_mark",
  245.           '##', $cite_key,$cite_mark,
  246.           ' ',
  247.           $harvard_left,
  248.           '##', $cite_key,$citeyear_mark,
  249.           $text ? ($harvard_agsm_cite_separator, $text):'',
  250.           $harvard_right,
  251.           "<\/A>",
  252.           $_);
  253.     }    
  254.     else {warn "Cannot find citation argument\n";}
  255. }
  256.  
  257.  
  258. sub do_cmd_citeasnounstar {
  259.     local($_) = @_;
  260.     local($text, $dummy) = &get_next_optional_argument;
  261.     s/$next_pair_pr_rx//o;
  262.     local($cite_key) = $2;
  263.     if ($cite_key) {
  264.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  265.     join ('',
  266.           "<A HREF=#$cite_key>$citekey_mark",
  267.           '##', $cite_key,$citefull_mark,
  268.           ' ',
  269.           $harvard_left,
  270.           '##', $cite_key,$citeyear_mark,
  271.           $text ? ($harvard_agsm_cite_separator, $text):'',
  272.           $harvard_right,
  273.           "<\/A>",
  274.           $_);
  275.     }    
  276.     else {warn "Cannot find citation argument\n";}
  277. }
  278.  
  279.  
  280. sub do_cmd_citeasnounstarstar {
  281.     local($_) = @_;
  282.     local($text, $dummy) = &get_next_optional_argument;
  283.     s/$next_pair_pr_rx//o;
  284.     local($cite_key) = $2;
  285.     if ($cite_key) {
  286.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  287.     join ('',
  288.           "<A HREF=#$cite_key>$citekey_mark",
  289.           '##', $cite_key,$citeshort_mark,
  290.           ' ',
  291.           $harvard_left,
  292.           '##', $cite_key,$citeyear_mark,
  293.           $text ? ($harvard_agsm_cite_separator, $text):'',
  294.           $harvard_right,
  295.           "<\/A>",
  296.           $_);
  297.     }    
  298.     else {warn "Cannot find citation argument\n";}
  299. }
  300.  
  301.  
  302.  
  303. #same as citeasnoun, but add the possessive 's
  304. #no multiple cites allowed !
  305.  
  306. sub do_cmd_possessivecite {
  307.     local($_) = @_;
  308.     local($text, $dummy) = &get_next_optional_argument;
  309.     s/$next_pair_pr_rx//o;
  310.     local($cite_key) = $2;
  311.     if ($cite_key) {
  312.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  313.     # The proper link $citefile#$cite_key will be substituted later
  314.         join('', "<A HREF=#$cite_key>$citekey_mark",
  315.          '##', $cite_key,$cite_mark,
  316.          '\'s ',
  317.          $harvard_left,
  318.          '##', $cite_key,$citeyear_mark,
  319.          $text? ($harvard_agsm_cite_separator, $text):'', 
  320.          $harvard_right,
  321.          "<\/A>",
  322.          $_);
  323.     }
  324.     else {warn "Cannot find citation argument\n";}
  325. }
  326.  
  327. sub do_cmd_possessivecitestar {
  328.     local($_) = @_;
  329.     local($text, $dummy) = &get_next_optional_argument;
  330.     s/$next_pair_pr_rx//o;
  331.     local($cite_key) = $2;
  332.     if ($cite_key) {
  333.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  334.     # The proper link $citefile#$cite_key will be substituted later
  335.         join('', "<A HREF=#$cite_key>$citekey_mark",
  336.          '##', $cite_key,$citefull_mark,
  337.          '\'s ',
  338.          $harvard_left,
  339.          '##', $cite_key,$citeyear_mark,
  340.          $text? ($harvard_agsm_cite_separator, $text):'', 
  341.          $harvard_right,
  342.          "<\/A>",
  343.          $_);
  344.     }
  345.     else {warn "Cannot find citation argument\n";}
  346. }
  347.  
  348. sub do_cmd_possessivecitestarstar {
  349.     local($_) = @_;
  350.     local($text, $dummy) = &get_next_optional_argument;
  351.     s/$next_pair_pr_rx//o;
  352.     local($cite_key) = $2;
  353.     if ($cite_key) {
  354.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  355.     # The proper link $citefile#$cite_key will be substituted later
  356.         join('', "<A HREF=#$cite_key>$citekey_mark",
  357.          '##', $cite_key,$citeshort_mark,
  358.          '\'s ',
  359.          $harvard_left,
  360.          '##', $cite_key,$citeyear_mark,
  361.          $text? ($harvard_agsm_cite_separator, $text):'', 
  362.          $harvard_right,
  363.          "<\/A>",
  364.          $_);
  365.     }
  366.     else {warn "Cannot find citation argument\n";}
  367. }
  368.  
  369.  
  370. #similar to citeasnoun, but only names
  371. #multiple arguments allowed, no link produced
  372. #no optional text argument
  373.  
  374. sub do_cmd_citename {
  375.     local($_) = @_;
  376.     s/$next_pair_pr_rx//o;
  377.     local($cite_key) = $2;
  378.     local ($first) = 1;
  379.     local ($result);
  380.     if ($cite_key) {
  381.     foreach $cite_key (split(/,/,$cite_key)) {
  382.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  383.         # The proper link $citefile#$cite_key will be substituted later
  384.             $result = join('', $result, 
  385.                ($first? '': $harvard_cite_separator),
  386.                "<A HREF=#$cite_key>$citekey_mark",
  387.                '##', $cite_key, $citename_mark, 
  388.                "</A>");
  389.         $first = 0;
  390.     }
  391.     join ('', $result, $_);
  392.     }
  393.     else {warn "Cannot find citation argument\n";}
  394. }
  395.  
  396. sub do_cmd_citenamestar {
  397.     local($_) = @_;
  398.     s/$next_pair_pr_rx//o;
  399.     local($cite_key) = $2;
  400.     local ($first) = 1 ;
  401.     local ($result);
  402.     if ($cite_key) {
  403.     foreach $cite_key (split(/,/,$cite_key)) {
  404.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  405.         # The proper link $citefile#$cite_key will be substituted later
  406.             $result = join('', $result,
  407.                ($first? '' : $harvard_cite_separator),
  408.                "<A HREF=#$cite_key>$citekey_mark",
  409.                '##', $cite_key,$citenamefull_mark, 
  410.                "</A>");
  411.         $first = 0;
  412.     }
  413.     join ('', $result, $_);
  414.     }
  415.     else {warn "Cannot find citation argument\n";}
  416. }
  417.  
  418. sub do_cmd_citenamestarstar {
  419.     local($_) = @_;
  420.     s/$next_pair_pr_rx//o;
  421.     local($cite_key) = $2;
  422.     local ($first) = 1 ;
  423.     local ($result);
  424.     if ($cite_key) {
  425.     foreach $cite_key (split(/,/,$cite_key)) {
  426.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  427.         # The proper link $citefile#$cite_key will be substituted later
  428.             $result = join('', $result,
  429.                ($first? '' : $harvard_cite_separator),
  430.                "<A HREF=#$cite_key>$citekey_mark",
  431.                '##', $cite_key,$citenameshort_mark, 
  432.                "</A>");
  433.         $first = 0;
  434.     }
  435.     join ('', $result, $_);
  436.     }
  437.     else {warn "Cannot find citation argument\n";}
  438. }
  439.  
  440.  
  441. #similar to cite, but only year
  442. #multiple arguments allowed, no link produced
  443. #no optional text argument
  444.  
  445. sub do_cmd_citeyear {
  446.     local($_) = @_;
  447.     s/$next_pair_pr_rx//o;
  448.     local($cite_key) = $2;
  449.     local ($first) = 1 ;
  450.     local ($result);
  451.     if ($cite_key) {
  452.     foreach $cite_key (split(/,/,$cite_key)) {
  453.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  454.         # The proper link $citefile#$cite_key will be substituted later
  455.         $result = join ('', $result, 
  456.                 ($first ? $harvard_left : $harvard_cite_separator),
  457.                 "<A HREF=#$cite_key>$citekey_mark",
  458.                 '##', $cite_key,$citeyear_mark, 
  459.                 "</A>");
  460.         $first = 0;
  461.     }
  462.     join('',$result, $harvard_right, $_); # closing bracket
  463.     }
  464.     else {warn "Cannot find citation argument\n";}
  465. }
  466.  
  467.  
  468. # citeyear without brackets
  469.  
  470. sub do_cmd_citeyearstar {
  471.     local($_) = @_;
  472.     s/$next_pair_pr_rx//o;
  473.     local($cite_key) = $2;
  474.     local ($first) = 1 ;
  475.     local ($result);
  476.     if ($cite_key) {
  477.     foreach $cite_key (split(/,/,$cite_key)) {
  478.         $cite_key =~ s/\W//g;      # Remove non alphanumeric characters
  479.         # The proper link $citefile#$cite_key will be substituted later
  480.         $result = join ('', $result, 
  481.                 ($first ? '' : $harvard_cite_separator),
  482.                 "<A HREF=#$cite_key>$citekey_mark",
  483.                 '##', $cite_key,$citeyear_mark, 
  484.                 "</A>");
  485.         $first = 0;
  486.     }
  487.     join('',$result, $_); # no brackets
  488.     }
  489.     else {warn "Cannot find citation argument\n";}
  490. }
  491.  
  492.  
  493.  
  494.  
  495. # the style commands
  496.  
  497. sub do_cmd_citationstyle{
  498.     local($_) = @_;
  499.     s/$next_pair_pr_rx//o;
  500.     $2;
  501.   switch: {
  502.       if ($2 =~ /dcu/){
  503.     $harvard_cite_separator = $harvard_dcu_cite_separator;
  504.     $harvard_year_separator = $harvard_dcu_year_separator;
  505.     $harvard_and = $harvard_dcu_and;
  506.     last switch; }
  507.       if ($2 =~ /agsm/) {
  508.     $harvard_cite_separator = $harvard_agsm_cite_separator;
  509.     $harvard_year_separator = $harvard_agsm_year_separator;
  510.     $harvard_and = $harvard_agsm_and;
  511.     last switch;}
  512.       warn 'unknown citation style $2';}
  513.     $_;
  514.  
  515.  
  516.  
  517. sub do_cmd_citationmode{
  518.     local($_) = @_;
  519.     s/$next_pair_pr_rx//o;
  520.     $2;
  521.   switch: {
  522.       if ($2 =~ /full/){
  523.     $harvard_full = 1;
  524.     $harvard_default = 0;
  525.     last switch; }
  526.       if ($2 =~ /abbr/) {
  527.     $harvard_full = 0;
  528.     $harvard_default = 0;
  529.     last switch;}
  530.       if ($2 =~ /default/) {
  531.     $harvard_full = 0;
  532.     $harvard_default = 1;
  533.     last switch;}
  534.       warn 'unknown citation mode $2';}
  535.     $_;
  536.  
  537.  
  538. sub do_cmd_harvardparenthesis{
  539.     local($_) = @_;
  540.     s/$next_pair_pr_rx//o;
  541.   switch: {
  542.       if ($2 =~ /round/){
  543.     $harvard_left = '\(';
  544.     $harvard_right = '\)';
  545.     $harvardyear_left = '\(';
  546.     $harvardyear_right = '\)';
  547.     last switch; }
  548.       if ($2 =~ /curly/) {
  549.     $harvard_left = '\{';
  550.     $harvard_right = '\}';
  551.     $harvardyear_left = '\{';
  552.     $harvardyear_right = '\}';
  553.     last switch;}
  554.       if ($2 =~ /square/) {
  555.     $harvard_left = '\[';
  556.     $harvard_right = '\]';
  557.     $harvardyear_left = '\[';
  558.     $harvardyear_right = '\]';
  559.     last switch;}
  560.       if ($2 =~ /angle/) {
  561.     $harvard_left = '<';
  562.     $harvard_right = '>';
  563.     $harvardyear_left = '<';
  564.     $harvardyear_right = '>';
  565.     last switch;}
  566.       warn 'unknown paranthesis type $2';}
  567.     $_
  568.  
  569.  
  570. sub do_cmd_harvardyearparenthesis{
  571.     local($_) = @_;
  572.     s/$next_pair_pr_rx//o;
  573.   switch: {
  574.       if ($2 =~ /round/){
  575.     $harvardyear_left = '\(';
  576.     $harvardyear_right = '\)';
  577.     last switch; }
  578.       if ($2 =~ /curly/) {
  579.     $harvardyear_left = '\{';
  580.     $harvardyear_right = '\}';
  581.     last switch;}
  582.       if ($2 =~ /square/) {
  583.     $harvardyear_left = '\[';
  584.     $harvardyear_right = '\]';
  585.     last switch;}
  586.       if ($2 =~ /angle/) {
  587.     $harvardyear_left = '<';
  588.     $harvardyear_right = '>';
  589.     last switch;}
  590.       warn 'unknown year paranthesis type $_';}
  591.     $_;
  592.  
  593.  
  594. # harvard symbols
  595.  
  596. sub do_cmd_harvardleft {
  597.     join('',$harvard_left,@_[0]);
  598. }
  599.  
  600. sub do_cmd_harvardright {
  601.     join('',$harvard_right,@_[0]);
  602. }
  603.  
  604. sub do_cmd_harvardyearleft {
  605.     join('',$harvardyear_left,@_[0]);
  606. }
  607.  
  608. sub do_cmd_harvardyearright {
  609.     join('',$harvardyear_right,@_[0]);
  610. }
  611.  
  612. sub do_cmd_harvardand {
  613.     join('',$harvard_and,@_[0]);
  614. }
  615.  
  616.  
  617.  
  618. # This command will only be encountered inside a thebibliography environment.
  619. # this should not occur in a file using harvard style
  620. # mainly unchanged, only a warning added
  621.  
  622. sub do_cmd_bibitem {
  623.     local($_) = @_;
  624.     # The square brackets may contain the label to be printed
  625.     warn "bibitem-command in harvard-style file\n Cannot extract all neccessary information for cites\n";
  626.     local($label, $dummy) = &get_next_optional_argument;
  627.     $label = ++$bibitem_counter unless $label; # Numerical labels 
  628.     s/$next_pair_pr_rx//o;
  629.     $cite_key = $2;
  630.     if ($cite_key) {
  631.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  632.     # Associate the cite_key with the printed label.
  633.     # The printed label will be substituted back into the document later.
  634.     $cite_info{$cite_key} = $label;
  635.     # Create an anchor around the citation
  636.     join('',"<DT><A NAME=\"$cite_key\"><B>$label</B></A><DD>", $_);
  637.     }
  638.     else {
  639.     warn "Cannot find bibitem labels\n";}
  640. }
  641.  
  642. # collect information from item and associate it with the
  643. # cite-key. Contrary to bibitem, the cite-key argument is not optional,
  644. # so no numeric cite-key has to be generated
  645.  
  646. sub do_cmd_harvarditem {
  647.     local($_) = @_;
  648.     # The square brackets may contain the short citation
  649.     local($abbr_cite, $dummy) = &get_next_optional_argument;
  650.     s/$next_pair_pr_rx//o;
  651.     local($full_cite)= $2;
  652.     $abbr_cite= $full_cite unless $abbr_cite;
  653.     s/$next_pair_pr_rx//o;
  654.     local($cite_year) = $2;
  655.     s/$next_pair_pr_rx//o;
  656.     local($cite_key) = $2;
  657.     if ($cite_key) {
  658.     $cite_key =~ s/\W//g;        # Remove non alphanumeric characters
  659.     # Associate the citation-infos with the cite-key.
  660.     # The infos will be substituted back into the document later,
  661.     # depending on the citation used
  662.     $cite_info_abbr {$cite_key} = $abbr_cite;
  663.     $cite_info_full {$cite_key} = $full_cite;
  664.     $cite_info_year {$cite_key} = $cite_year;
  665.     $cite_info_first {$cite_key} = 1;
  666.     # Create an anchor around the citation
  667.     join('',"<DT><A NAME=\"$cite_key\">- </A><DD>", $_);
  668.     }
  669.     else {
  670.     warn "Cannot find bibitem labels\n";}
  671. }
  672.  
  673.  
  674. ##
  675. ## to allow bibcard to produce URL links:
  676. ## same as htmladdnormallink, but only one argument (both link and text)
  677.  
  678. sub do_cmd_harvardurl{
  679.     local($_) = @_;
  680.     local($url);
  681.     s/$next_pair_pr_rx/$url = $2; ''/eo;
  682.     join('',do {qq/<B>URL:<\/B><A HREF="$url">$url<\/A>/;},$_);
  683. }
  684.  
  685.  
  686.  
  687. # this onle has to be extended to search for citename_mark and
  688. # citeyear_mark as well
  689. # the appropriate entries should have been produced by do_cmd_harvarditem
  690.  
  691. sub replace_cite_references {
  692.    s/##(\w+)$cite_mark/&help_replace_cites(\1)/ge;
  693.    s/##(\w+)$citefull_mark/&help_replace_fullcites(\1)/ge;
  694.    s/##(\w+)$citeshort_mark/&help_replace_shortcites(\1)/ge;
  695.    s/##(\w+)$citename_mark/&help_replace_name($1)/ge;
  696.    s/##(\w+)$citenamefull_mark/$cite_info_full{\1}/g;
  697.    s/##(\w+)$citenameshort_mark/$cite_info_short{\1}/g;
  698.    s/##(\w+)$citeyear_mark/$cite_info_year{\1}/g;
  699.    s/#(\w+)>$citekey_mark/$citefile#\1>/g;
  700.    $_
  701. }
  702.  
  703.  
  704. #return full or abbreviated cite text
  705. sub help_replace_cites {
  706.     local ($key)= @_[0];
  707.     $cite_info_first{$key}= 0;    # not the first time anymore
  708.     if ($harvard_full || ($cite_info_first{$key} && $harvard_default)) {
  709.     $cite_info_full{$key}; # full citation
  710.     }
  711.     else{
  712.     $cite_info_abbr{$key}; # abbreviated citation
  713.     }
  714. }  
  715.  
  716. sub help_replace_shortcites {
  717.     local ($key)= @_[0];
  718.     $cite_info_first{$key}= 0;    # not the first time anymore
  719.     $cite_info_abbr{$key}; # abbreviated citation
  720. }  
  721.  
  722. sub help_replace_fullcites {
  723.     local ($key)= @_[0];
  724.     $cite_info_first{$key}= 0;    # not the first time anymore
  725.     $cite_info_full{$key}; # full citation
  726. }  
  727.  
  728. sub help_replace_name {
  729.     local ($key)= @_[0];
  730.     if ($harvard_full || ($cite_info_first{$key} && $harvard_default)) {
  731.     $cite_info_full{$key}; # full citation
  732.     }
  733.     else{
  734.     $cite_info_abbr{$key}; # abbreviated citation
  735.     }
  736. }
  737.  
  738.  
  739. #this one has to be changes as well, so that it finds all citemarks
  740.  
  741. sub remove_general_markers {
  742.     s/$lof_mark/<UL>$figure_captions<\/UL>/o;
  743.     s/$lot_mark/<UL>$table_captions<\/UL>/o;
  744.     s/$bbl_mark/$citations/o;
  745.     &add_toc if (/$toc_mark/);
  746.     &add_idx if (/$idx_mark/);
  747.     &replace_cross_references if /$cross_ref_mark/;
  748.     &replace_external_references if /$external_ref_mark/;
  749.     &replace_cite_references;  #just take the if out (not really neccessary)
  750. }  
  751.  
  752.  
  753. 1;                # Not really necessary...
  754.  
  755.  
  756.  
  757. # T.S.: added the starstar option 
  758. # If a normalized command name exists, return it.
  759. sub normalize {
  760.     local($cmd) = @_;
  761.     local($ncmd);
  762.     if ($ncmd = $normalize{$cmd}) {
  763.     $ncmd}
  764.     elsif ($cmd =~ s/[*]/star/g) {
  765.     $cmd }
  766.     elsif ($cmd =~ s/^@/tex/) {
  767.     $cmd}
  768.     else {$cmd}
  769. }
  770.  
  771.  
  772. # does not really belong to harvard.perl, but as a general improvement
  773.  
  774.  
  775. sub do_cmd_and {
  776.     join('',"<p>", @_[0]);         #make a paragraph brake of it 
  777. }
  778.  
  779. sub do_cmd_newline {
  780.     join('',"<br>", @_[0]);
  781. }
  782.  
  783.